package com.qianxx.component.activity.chart.slip_stick_chart;

import android.graphics.Color;
import android.os.Bundle;

import com.qianxx.component.R;
import com.qianxx.component.activity.base.BaseActivity;
import com.qianxx.viewlibrary.chart.axis.Axis;
import com.qianxx.viewlibrary.chart.entity.IChartData;
import com.qianxx.viewlibrary.chart.entity.IStickEntity;
import com.qianxx.viewlibrary.chart.entity.ListChartData;
import com.qianxx.viewlibrary.chart.entity.StickEntity;
import com.qianxx.viewlibrary.chart.event.IZoomable;
import com.qianxx.viewlibrary.chart.view.SlipStickChart;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class SlipStickChartActivity extends BaseActivity {
    @BindView(R.id.slip_stick_chart)
    SlipStickChart slip_stick_chart;

    List<IStickEntity> vol;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_slip_stick_chart);
        ButterKnife.bind(this);

        initData();
        initView();
    }

    private void initData() {
        List<IStickEntity> stick = new ArrayList<>();

        stick.add(new StickEntity(406000, 0, "20110825"));
        stick.add(new StickEntity(232000, 0, "20110824"));
        stick.add(new StickEntity(355000, 0, "20110823"));
        stick.add(new StickEntity(437000, 0, "20110822"));
        stick.add(new StickEntity(460000, 0, "20110819"));
        stick.add(new StickEntity(422000, 0, "20110818"));
        stick.add(new StickEntity(502000, 0, "20110817"));
        stick.add(new StickEntity(509000, 0, "20110816"));
        stick.add(new StickEntity(110000, 0, "20110815"));
        stick.add(new StickEntity(110000, 0, "20110812"));
        stick.add(new StickEntity(310000, 0, "20110811"));
        stick.add(new StickEntity(210000, 0, "20110810"));
        stick.add(new StickEntity(211000, 0, "20110809"));
        stick.add(new StickEntity(577000, 0, "20110808"));
        stick.add(new StickEntity(493000, 0, "20110805"));
        stick.add(new StickEntity(433000, 0, "20110804"));
        stick.add(new StickEntity(479000, 0, "20110803"));
        stick.add(new StickEntity(360000, 0, "20110802"));
        stick.add(new StickEntity(437000, 0, "20110801"));
        stick.add(new StickEntity(504000, 0, "20110729"));
        stick.add(new StickEntity(520000, 0, "20110728"));
        stick.add(new StickEntity(494000, 0, "20110727"));
        stick.add(new StickEntity(312000, 0, "20110726"));
        stick.add(new StickEntity(424000, 0, "20110725"));
        stick.add(new StickEntity(557000, 0, "20110722"));
        stick.add(new StickEntity(596000, 0, "20110721"));
        stick.add(new StickEntity(311000, 0, "20110720"));
        stick.add(new StickEntity(312000, 0, "20110719"));
        stick.add(new StickEntity(312000, 0, "20110718"));
        stick.add(new StickEntity(312000, 0, "20110715"));
        stick.add(new StickEntity(410000, 0, "20110714"));
        stick.add(new StickEntity(311000, 0, "20110713"));
        stick.add(new StickEntity(210000, 0, "20110712"));
        stick.add(new StickEntity(410000, 0, "20110711"));
        stick.add(new StickEntity(214000, 0, "20110708"));
        stick.add(new StickEntity(312000, 0, "20110707"));
        stick.add(new StickEntity(212000, 0, "20110706"));
        stick.add(new StickEntity(414000, 0, "20110705"));
        stick.add(new StickEntity(310000, 0, "20110704"));
        stick.add(new StickEntity(210000, 0, "20110701"));
        stick.add(new StickEntity(190000, 0, "20110630"));
        stick.add(new StickEntity(210000, 0, "20110629"));
        stick.add(new StickEntity(116000, 0, "20110628"));
        stick.add(new StickEntity(142000, 0, "20110627"));
        stick.add(new StickEntity(524000, 0, "20110624"));
        stick.add(new StickEntity(246000, 0, "20110623"));
        stick.add(new StickEntity(432000, 0, "20110622"));
        stick.add(new StickEntity(352000, 0, "20110621"));
        stick.add(new StickEntity(243000, 0, "20110620"));
        stick.add(new StickEntity(165000, 0, "20110617"));
        stick.add(new StickEntity(554000, 0, "20110616"));
        stick.add(new StickEntity(552000, 0, "20110615"));
        stick.add(new StickEntity(431000, 0, "20110614"));
        stick.add(new StickEntity(317000, 0, "20110613"));
        stick.add(new StickEntity(512000, 0, "20110610"));
        stick.add(new StickEntity(283000, 0, "20110609"));
        stick.add(new StickEntity(144000, 0, "20110608"));
        stick.add(new StickEntity(273000, 0, "20110607"));
        stick.add(new StickEntity(278000, 0, "20110603"));
        stick.add(new StickEntity(624000, 0, "20110602"));
        stick.add(new StickEntity(217000, 0, "20110601"));
        stick.add(new StickEntity(116000, 0, "20110531"));
        stick.add(new StickEntity(191000, 0, "20110530"));
        stick.add(new StickEntity(204000, 0, "20110527"));
        stick.add(new StickEntity(236000, 0, "20110526"));
        stick.add(new StickEntity(421000, 0, "20110525"));
        stick.add(new StickEntity(114000, 0, "20110524"));
        stick.add(new StickEntity(403000, 0, "20110523"));
        stick.add(new StickEntity(205000, 0, "20110520"));
        stick.add(new StickEntity(328000, 0, "20110519"));
        stick.add(new StickEntity(109000, 0, "20110518"));
        stick.add(new StickEntity(286000, 0, "20110517"));
        stick.add(new StickEntity(103000, 0, "20110516"));
        stick.add(new StickEntity(114000, 0, "20110513"));
        stick.add(new StickEntity(107000, 0, "20110512"));
        stick.add(new StickEntity(106000, 0, "20110511"));
        stick.add(new StickEntity(146000, 0, "20110510"));
        stick.add(new StickEntity(105000, 0, "20110509"));
        stick.add(new StickEntity(312000, 0, "20110506"));
        stick.add(new StickEntity(530000, 0, "20110505"));
        stick.add(new StickEntity(275000, 0, "20110504"));
        stick.add(new StickEntity(432000, 0, "20110503"));

        this.vol = new ArrayList<>();
        for (int i = stick.size(); i > 0; i--) {
            this.vol.add(stick.get(i - 1));
        }
    }

    private void initView() {
        slip_stick_chart.setAxisXColor(Color.LTGRAY);
        slip_stick_chart.setAxisYColor(Color.LTGRAY);
        slip_stick_chart.setLatitudeColor(Color.GRAY);
        slip_stick_chart.setLongitudeColor(Color.GRAY);
        slip_stick_chart.setBorderColor(Color.LTGRAY);
        slip_stick_chart.setLongitudeFontColor(Color.BLACK);
        slip_stick_chart.setLatitudeFontColor(Color.BLACK);
        slip_stick_chart.setDataQuadrantPaddingTop(6);
        slip_stick_chart.setDataQuadrantPaddingBottom(1);
        slip_stick_chart.setDataQuadrantPaddingLeft(1);
        slip_stick_chart.setDataQuadrantPaddingRight(1);
        slip_stick_chart.setAxisXPosition(Axis.AXIS_X_POSITION_BOTTOM);
        slip_stick_chart.setAxisYPosition(Axis.AXIS_Y_POSITION_LEFT);

        // slipstickchart.setLatitudeNum(2);
        // slipstickchart.setLongitudeNum(3);
        // slipstickchart.setMaxValue(600000);
        // slipstickchart.setMinValue(100);

        slip_stick_chart.setDisplayFrom(10);
        slip_stick_chart.setDisplayNumber(30);
        slip_stick_chart.setMinDisplayNumber(5);
        slip_stick_chart.setZoomBaseLine(IZoomable.ZOOM_BASE_LINE_CENTER);
        slip_stick_chart.setDisplayLongitudeTitle(true);
        slip_stick_chart.setDisplayLatitudeTitle(true);
        slip_stick_chart.setDisplayLatitude(true);
        slip_stick_chart.setDisplayLongitude(true);
        slip_stick_chart.setBackgroundColor(Color.WHITE);
        slip_stick_chart.setDataMultiple(100);
        slip_stick_chart.setAxisYDecimalFormat("#,##0.00");
        slip_stick_chart.setAxisXDateTargetFormat("yyyy/MM/dd");
        slip_stick_chart.setAxisXDateSourceFormat("yyyyMMdd");
        slip_stick_chart.setDisplayBorder(false);
        slip_stick_chart.setCrossLinesColor(Color.BLACK);
        IChartData<IStickEntity> vol = new ListChartData<>(this.vol);

        slip_stick_chart.setStickData(vol);
    }

    @Override
    public String setTitle() {
        return "SlipStickChart";
    }
}
